#ifndef __LIBMAD_DRIVER_H__
#define __LIBMAD_DRIVER_H__

#include "mad.h"
#include <cstdint>
#include <cstdio>

class Libmad_driver {
public:
    static Libmad_driver& getInstance() {
        static Libmad_driver instance;
        return instance;
    }
    // 删除拷贝构造函数和赋值运算符
    Libmad_driver(const Libmad_driver&) = delete;
    Libmad_driver& operator=(const Libmad_driver&) = delete;

    void initialize(
        const char* new_filename, int (*outputHandler)(const short* pcm, size_t num_samples, int frq, int channels));

private:
    Libmad_driver();
    ~Libmad_driver();

    static enum mad_flow input(void* data, struct mad_stream* stream);
    static inline signed int scale(mad_fixed_t sample);
    static enum mad_flow output(void* data, struct mad_header const* header, struct mad_pcm* pcm);
    static enum mad_flow error(void* data, struct mad_stream* stream, struct mad_frame* frame);

    struct mp3_file;
    mp3_file* mp3_data_ = nullptr;
};

#endif    // !__
